import React from 'react';
import { connect } from 'dva';
import _ from 'lodash';
// import { configConsumerProps } from 'antd/lib/config-provider';
import btnsConfig from './config';

const AuthorizedButton = props => {
  const { Permissions, children, authority } = props;
  const foudItems = _.filter(btnsConfig, config => config.code === authority);
  if (foudItems && foudItems.length > 0) {
    const { permissionCode } = foudItems[0];
    if (_.includes(Permissions.buttons, permissionCode)) {
      return <>{children}</>;
    }
  }
  return <></>;
  // return <>{children}</>;
};

export default connect(({ Permissions }) => ({
  Permissions,
}))(AuthorizedButton);
